package com.swan.security.exception;

import com.swan.web.domain.BaseResponse;
import com.swan.web.exception.IExceptionHandler;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.authentication.BadCredentialsException;

/** 401 未登录
 * @author zongf
 * @date 2025-02-20
 **/
public class BadCredentialsExceptionHandler implements IExceptionHandler {

    @Override
    public BaseResponse handle(Throwable throwable) {
        return new BaseResponse(httpStatus(), throwable.getMessage());
    }

    @Override
    public Class<? extends Throwable> handleType() {
        return BadCredentialsException.class;
    }

    @Override
    public int getOrder() {
        return 0;
    }

    @Override
    public int httpStatus() {
        return HttpServletResponse.SC_UNAUTHORIZED;
    }

}
